package com.gupaoedu.pattern.singleton.hungry;

/**
 * 2019/5/10
 * created by chenpp
 */
/**
 * 饿汉式单例
 * 在类加载的时候就初始化的单例
 * 优点:线程安全
 * 缺点:对于没有使用过的类也会有初始化的单例,会造成内存浪费
 *
 * */
public class HungryStaticSingleton {
    private HungryStaticSingleton(){}
    private static HungryStaticSingleton instance ;
    static {
        instance = new HungryStaticSingleton();
    }
    public static HungryStaticSingleton getInstance(){
        return  instance;
    }
}
